<template>
  <div class="nofound_container">
    <img src="@/assets/img/404.jpg" alt="" />
    <p>
      <span class="text">没有找到页面，即将返回首页 </span
      ><span class="time">{{ state.sms.time }}s</span>
    </p>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
const router = useRouter()
const state = reactive({
  sms: {
    start: false,
    time: 10,
    code: null,
    timer: null
  }
})

onMounted(() => {
  state.sms.start = true
  let beforeTime = getTime()
  if (state.sms.timer !== undefined) {
    clearInterval(state.sms.timer)
  }
  state.sms.timer = setInterval(() => {
    if (state.sms.time > 1) {
      state.sms.time -= +((getTime() - beforeTime) / 1000).toFixed(0)
    } else {
      resetSendSMSTime()
    }
    beforeTime = getTime()
  }, 1000)
})

function resetSendSMSTime() {
  state.sms.start = false
  state.sms.time = 10
  clearInterval(state.sms.timer)
  router.push({ name: 'Home' })
}

function getTime() {
  return new Date().getTime()
}
</script>
<style scoped lang="less">
.nofound_container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  img {
    width: 500px;
    height: auto;
    display: block;
    margin: 0 auto;
  }
  p {
    text-align: center;
    .time {
      font-family: SourceHanSansCN-Bold;
      font-size: 24px;
      font-weight: bold;
      color: #333333;
      margin-right: 5px;
    }
    .text {
      font-size: 18px;
      font-weight: 500;
      color: #666666;
    }
  }
}
</style>
